using System;
using System.IO;


namespace Weazel.Toad.TextEditor.Document
{
	/// <summary>
	/// This interface represents a container which holds a text sequence and
	/// all necessary information about it. It is used as the base for a text editor.
	/// </summary>
	public class DocumentFactory
	{
		/// <remarks>
		/// Creates a new <see cref="DefaultDocument"/> object. Only create
		/// <see cref="DefaultDocument"/> with this method.
		/// </remarks>
		public Document CreateDocument()
		{
			Document doc = new Document();
			doc.FormattingStrategy    = new DefaultFormattingStrategy();
			doc.LineManager          = new LineManager(doc, null);
			doc.MarkerStrategy       = new MarkerStrategy(doc);
			return doc;
		}
		
		/// <summary>
		/// Creates a new document and loads the given file
		/// </summary>
		public Document CreateFromFile(string fileName)
		{
			Document document = CreateDocument();
			StreamReader stream = File.OpenText(fileName);
			document.TextContent = stream.ReadToEnd();
			stream.Close();
			return document;
		}
	}
}
